function survivalCurve(survivalTime,groups,censorvec,legendLabels)


%%%%%
% This function plots unadjusted survival curves and 95% confidence bounds for different groups.
%
% Inputs:
% survivalTime - 1D vector containing survival time.
% groups - 1D vector indicating different groups by distinct numbers, should correspond to the elements in survivalTime.
% censorvec - 1D boolean vector indicating right-censored data; 0 = not censored, 1 = right-censored. Should correspond to the elements in survivalTime.
% legendLabels - cell array of strings containing legend labels in ascending order of group labels.
%
% Written by Joon Lee, Feb. 16, 2011
%%%%%


groups= +groups;
allGroups=min(groups):max(groups);
colors={'b' 'r' 'g' 'c' 'm' 'y' 'k' 'w'};
legendLabelsCI={};
figure
hold on

for i=1:length(allGroups)    
    idx= groups==allGroups(i);        
    [f,x,flo,fup]=ecdf(survivalTime(idx),'censoring',censorvec(idx),'function','survivor');
    stairs(x,f,colors{mod(i,8)},'LineWidth',2)
    stairs(x,flo,[colors{mod(i,8)} ':'])
    stairs(x,fup,[colors{mod(i,8)} ':'])
    legendLabelsCI=[legendLabelsCI legendLabels{i} [legendLabels{i} ' Lower Bound'] [legendLabels{i} ' Upper Bound']];
end

xlabel('Survival Time')
ylabel('Survival Fraction')
legend(legendLabelsCI)
